import Vue from 'vue';
import router from 'vue-router'; /* 导入路由 */
import Login from '../views/Login.vue'; /* 导入其他组件 */
import Main from '../views/Main.vue'; /* 导入其他组件 */
import User from '../views/adminuser/User.vue'; 
import Role from '../views/role/Role.vue'; 
import Menu from '../views/menu/Menu.vue'; 
import Dept from '../views/dept/Dept.vue'; 
import Event from '../views/event/Events.vue';
import EventType from '../views/eventtype/EventType.vue';
Vue.use(router)

/* 定义组件路由 */
var rout = new router({
		routes: [
			{
				path: '/login',
				component: Login
			},
			{
				path: '/main',
				component: Main,
				children:[
					{
						path:"/user",
						component:User
					},
					{
						path:"/role",
						component:Role
					},
					{
						path:"/menu",
						component:Menu
					},
					{
						path:"/dept",
						component:Dept
					},
					{
						path:"/event",
						component:Event
					},
					{
						path:"/eventType",
						component:EventType
					}
					
				]
			}
		]
	});
	// 路由导航守护
	rout.beforeEach((to,from,next)=>{
		if(to.path=='/login'){//如果用户访问的登录页，直接放行
			return next();
		}else{
			var token = window.sessionStorage.getItem("token");
			if(token==null){
				return next("/login");
		}else{
				next();
		}
	} 
 })

//导出路由对象
export default rout;

